home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995 August: Tool Chest / Dev.CD Aug 95 TC / Dev.CD Aug 95 TC.toast / Tool Chest / Interfaces / UniversalInterfaces 2.0 / PInterfaces / Translation.p < prev    next >
Encoding:
Text File  |  1995-04-18  |  11.7 KB  |  319 lines  |  [TEXT/MPS ]

  1. {
  2.      File:        Translation.p
  3.  
  4.      Contains:    Translation Manager (Macintosh Easy Open) Interfaces.
  5.  
  6.      Version:    Technology:    Macintosh Easy Open 1.1
  7.                  Package:    Universal Interfaces 2.0 in “MPW Latest” on ETO #17
  8.  
  9.      Copyright:    © 1984-1995 by Apple Computer, Inc.
  10.                  All rights reserved.
  11.  
  12.      Bugs?:        If you find a problem with this file, use the Apple Bug Reporter
  13.                  stack.  Include the file and version information (from above)
  14.                  in the problem description and send to:
  15.                      Internet:    apple.bugs@applelink.apple.com
  16.                      AppleLink:    APPLE.BUGS
  17.  
  18. }
  19.  
  20. {$IFC UNDEFINED UsingIncludes}
  21. {$SETC UsingIncludes := 0}
  22. {$ENDC}
  23.  
  24. {$IFC NOT UsingIncludes}
  25.  UNIT Translation;
  26.  INTERFACE
  27. {$ENDC}
  28.  
  29. {$IFC UNDEFINED __TRANSLATION__}
  30. {$SETC __TRANSLATION__ := 1}
  31.  
  32. {$I+}
  33. {$SETC TranslationIncludes := UsingIncludes}
  34. {$SETC UsingIncludes := 1}
  35.  
  36.  
  37. {$IFC UNDEFINED __TYPES__}
  38. {$I Types.p}
  39. {$ENDC}
  40. {    ConditionalMacros.p                                            }
  41.  
  42. {$IFC UNDEFINED __FILES__}
  43. {$I Files.p}
  44. {$ENDC}
  45. {    MixedMode.p                                                    }
  46. {    OSUtils.p                                                    }
  47. {        Memory.p                                                }
  48.  
  49. {$IFC UNDEFINED __COMPONENTS__}
  50. {$I Components.p}
  51. {$ENDC}
  52.  
  53. {$IFC UNDEFINED __TRANSLATIONEXTENSIONS__}
  54. {$I TranslationExtensions.p}
  55. {$ENDC}
  56. {    Quickdraw.p                                                    }
  57. {        QuickdrawText.p                                            }
  58.  
  59. {$PUSH}
  60. {$ALIGN MAC68K}
  61. {$LibExport+}
  62.     
  63. TYPE
  64.     DocOpenMethod = INTEGER;
  65.  
  66.  
  67. CONST
  68.     domCannot                    = 0;
  69.     domNative                    = 1;
  70.     domTranslateFirst            = 2;
  71.     domWildcard                    = 3;
  72.  
  73. { 0L terminated array of OSTypes, or FileTypes}
  74.     
  75. TYPE
  76.     TypesBlock = ARRAY [0..63] OF OSType;
  77.  
  78.     TypesBlockPtr = ^OSType;
  79.  
  80. { Progress dialog resource ID}
  81.  
  82. CONST
  83.     kTranslationScrapProgressDialogID = -16555;
  84.  
  85. { block of data that describes how to translate}
  86.  
  87. TYPE
  88.     FileTranslationSpec = RECORD
  89.         componentSignature:        OSType;
  90.         translationSystemInfo:    Ptr;
  91.         src:                    FileTypeSpec;
  92.         dst:                    FileTypeSpec;
  93.     END;
  94.  
  95.     FileTranslationSpecArrayPtr = ^FileTranslationSpec;
  96.  
  97. {****************************************************************************************
  98. *   GetFileTypesThatAppCanNativelyOpen
  99. *  This routine returns a list of all FileTypes that an application can open by itself
  100. *  Enter:    appVRefNumHint        volume where application resides (can be wrong, and if is, will be used as a starting point)
  101. *             appSignature        signature (creator) of application
  102. *             nativeTypes            pointer to a buffer to be filled with up to 64 FileTypes
  103. *  Exit:    nativeTypes            zero terminated array of FileTypes that can be opened by app
  104. }
  105.  
  106. FUNCTION GetFileTypesThatAppCanNativelyOpen(appVRefNumHint: INTEGER; appSignature: OSType; VAR nativeTypes: FileType): OSErr;
  107.     {$IFC NOT GENERATINGCFM}
  108.     INLINE $701C, $ABFC;
  109.     {$ENDC}
  110. {****************************************************************************************
  111. *  ExtendFileTypeList
  112. *  This routine makes a new list of file types that can be translated into a type in the given list
  113. *  Used by StandardFile
  114. *  Enter:    originalTypeList        pointer to list of file types that can be opened
  115. *             numberOriginalTypes        number of file types in orgTypeList
  116. *              extendedTypeList        pointer to a buffer to be filled with file types
  117. *             numberExtendedTypes        max number of file types that can be put in extendedTypeList
  118. *  Exit:    extendedTypeList        buffer filled in with file types that can be translated
  119. *             numberExtendedTypes        number of file types put in extendedTypeList
  120. }
  121. FUNCTION ExtendFileTypeList({CONST}VAR originalTypeList: FileType; numberOriginalTypes: INTEGER; VAR extendedTypeList: FileType; VAR numberExtendedTypes: INTEGER): OSErr;
  122.     {$IFC NOT GENERATINGCFM}
  123.     INLINE $7009, $ABFC;
  124.     {$ENDC}
  125. {****************************************************************************************
  126. *  This routine checks if a file can be opened by a particular application.
  127. *  If so, it returns if it needs to be translated first, and if so then how.
  128. *  The FileTypes that the app can open are specified by nativelyOpenableTypes,
  129. *  or if it is NULL, GetFileTypesThatAppCanNativelyOpen is called.
  130. *  Enter:    targetDocument        document to check if it can be opened
  131. *             appVRefNumHint        vRefNum of application to open doc ( can be wrong, and if is, will be used as a starting point)
  132. *             appSignature        signature (creator) of application to open doc
  133. *             nativeTypes            zero terminated list of FileTypes app can open natively, or NULL to use default list
  134. *             onlyNative            whether to consider if document can be translated before opening
  135. *             howToOpen            pointer to buffer in which to put how the document can be opened
  136. *             howToTranslate        pointer to buffer in which to put a FileTranslationSpec record
  137. *  Exit:    howToOpen            whether file needs to be translated to be read
  138. *             howToTranslate        if file can be translated, buffer filled in with how to translate
  139. *             returns                noErr, noPrefAppErr
  140. }
  141. FUNCTION CanDocBeOpened({CONST}VAR targetDocument: FSSpec; appVRefNumHint: INTEGER; appSignature: OSType; {CONST}VAR nativeTypes: FileType; onlyNative: BOOLEAN; VAR howToOpen: DocOpenMethod; VAR howToTranslate: FileTranslationSpec): OSErr;
  142.     {$IFC NOT GENERATINGCFM}
  143.     INLINE $701E, $ABFC;
  144.     {$ENDC}
  145. {****************************************************************************************
  146. *  GetFileTranslationPaths
  147. *  This routine returns a list of all ways a translation can occure to or from a FileType.
  148. *  The app is checked to exist.  The hint for each app is the VRefNum and DTRefNum
  149. *  Enter:    srcDoc            source file or NULL for all matches
  150. *             dstDoc            destination FileType or NULL for all matches
  151. *             maxResultCount
  152. *             resultBuffer
  153. *  Exit:    number of paths
  154. }
  155. FUNCTION GetFileTranslationPaths(VAR srcDocument: FSSpec; dstDocType: FileType; maxResultCount: INTEGER; resultBuffer: FileTranslationSpecArrayPtr): INTEGER;
  156.     {$IFC NOT GENERATINGCFM}
  157.     INLINE $7038, $ABFC;
  158.     {$ENDC}
  159. {****************************************************************************************
  160. *  GetPathFromTranslationDialog
  161. *  This routine, with a given document, application, and a passed typelist will display the
  162. *  Macintosh Easy Open translation dialog allowing the user to make a choice.  The choice
  163. *  made will be written as a preference (so the next call to CanDocBeOpened() will work).
  164. *  The routine returns the translation path information.
  165. *  Enter:    theDocument            FSSpec to document to open
  166. *             theApplication        FSSpec to application to open document
  167. *             typeList            Nil terminated list of FileType's (e.g. SFTypeList-like) of types
  168. *                                 you would like the documented translated to.  Order most perferred
  169. *                                 to least.
  170. *  Exit:    howToOpen            Translation method needed to open document
  171. *             howToTranslate        Translation specification
  172. *             returns                Any errors that might occur.
  173. }
  174. FUNCTION GetPathFromTranslationDialog({CONST}VAR theDocument: FSSpec; {CONST}VAR theApplication: FSSpec; typeList: TypesBlockPtr; VAR howToOpen: DocOpenMethod; VAR howToTranslate: FileTranslationSpec): OSErr;
  175.     {$IFC NOT GENERATINGCFM}
  176.     INLINE $7037, $ABFC;
  177.     {$ENDC}
  178. {****************************************************************************************
  179. *   TranslateFile
  180. *  This routine reads a file of one format and writes it to another file in another format. 
  181. *  The information on how to translated is generated by the routine CanDocBeOpened.
  182. *  TranslateFile calls through to the TranslateFile Extension's DoTranslateFile routine.  
  183. *  The destination file must not exist.  It is created by this routine.  
  184. *  Enter:    sourceDocument            input file to translate
  185. *             destinationDocument        output file of translation
  186. *             howToTranslate            pointer to info on how to translate
  187. *  Exit:    returns                    noErr, badTranslationSpecErr 
  188. }
  189. FUNCTION TranslateFile({CONST}VAR sourceDocument: FSSpec; {CONST}VAR destinationDocument: FSSpec; {CONST}VAR howToTranslate: FileTranslationSpec): OSErr;
  190.     {$IFC NOT GENERATINGCFM}
  191.     INLINE $700C, $ABFC;
  192.     {$ENDC}
  193. {****************************************************************************************
  194. *   GetDocumentKindString
  195. *  This routine returns the string the Finder should show for the "kind" of a document
  196. *  in the GetInfo window and in the kind column of a list view.  
  197. *  Enter:    docVRefNum        The volume containing the document
  198. *             docType            The catInfo.fdType of the document
  199. *             docCreator        The catInfo.fdCreator of the document
  200. *             kindString        pointer to where to return the string
  201. *  Exit:    kindString        pascal string.  Ex: "\pSurfCalc spreadsheet"
  202. *             returns            noErr, or afpItemNoFound if kind could not be determined
  203. }
  204. FUNCTION GetDocumentKindString(docVRefNum: INTEGER; docType: OSType; docCreator: OSType; VAR kindString: Str63): OSErr;
  205.     {$IFC NOT GENERATINGCFM}
  206.     INLINE $7016, $ABFC;
  207.     {$ENDC}
  208. {****************************************************************************************
  209. *  GetTranslationExtensionName
  210. *  This routine returns the translation system name from a specified TranslationSpec
  211. *  Enter:    translationMethod    The translation path to get the translation name from
  212. *  Exit:    extensionName        The name of the translation system
  213. *             returns                Any errors that might occur
  214. }
  215. FUNCTION GetTranslationExtensionName({CONST}VAR translationMethod: FileTranslationSpec; VAR extensionName: Str31): OSErr;
  216.     {$IFC NOT GENERATINGCFM}
  217.     INLINE $7036, $ABFC;
  218.     {$ENDC}
  219. {****************************************************************************************
  220. *  GetScrapDataProcPtr
  221. *  This is a prototype for the function you must supply to TranslateScrap. It is called to 
  222. *  get the data to be translated.  The first call TranslateScrap will make to this is to
  223. *  ask for the 'fmts' data.  That is a special.   You should resize and fill in the handle
  224. *  with a list all the formats that you have available to be translated, and the length of each.
  225. *  (See I.M. VI 4-23 for details of 'fmts').  It will then be called again asking for one of  
  226. *  the formats that 'fmts' list said was available.
  227. *  Enter:    requestedFormat            Format of data that TranslateScrap needs.
  228. *             dataH                    Handle in which to put the requested data
  229. *             srcDataGetterRefCon        Extra parameter for you passed to TranslateScrap
  230. *             
  231. *  Exit:    dataH                    Handle is resized and filled with data in requested format
  232. }
  233. TYPE
  234.     GetScrapDataProcPtr = ProcPtr;  { FUNCTION GetScrapData(requestedFormat: ScrapType; dataH: Handle; srcDataGetterRefCon: UNIV Ptr): OSErr; }
  235.     GetScrapDataUPP = UniversalProcPtr;
  236.  
  237. CONST
  238.     uppGetScrapDataProcInfo = $00000FE0; { FUNCTION (4 byte param, 4 byte param, 4 byte param): 2 byte result; }
  239.  
  240. FUNCTION NewGetScrapDataProc(userRoutine: GetScrapDataProcPtr): GetScrapDataUPP;
  241.     {$IFC NOT GENERATINGCFM }
  242.     INLINE $2E9F;
  243.     {$ENDC}
  244.  
  245. FUNCTION CallGetScrapDataProc(requestedFormat: ScrapType; dataH: Handle; srcDataGetterRefCon: UNIV Ptr; userRoutine: GetScrapDataUPP): OSErr;
  246.     {$IFC NOT GENERATINGCFM}
  247.     INLINE $205F, $4E90;
  248.     {$ENDC}
  249.     
  250. TYPE
  251.     GetScrapData = GetScrapDataUPP;
  252.  
  253. {****************************************************************************************
  254. *  TranslateScrap
  255. *  This routine resizes the destination handle and fills it with data of the requested format.
  256. *  The data is generated by translated one or more source formats of data supplied by
  257. *  the procedure srcDataGetter.  
  258. *  This routine is automatically called by GetScrap and ReadEdition.  You only need to call
  259. *  this if you need to translated scrap style data, but are not using the ScrapMgr or EditionMgr.
  260. *  Enter:    sourceDataGetter            Pointer to routine that can get src data
  261. *             sourceDataGetterRefCon        Extra parameter for dataGetter
  262. *             destinationFormat            Format of data desired
  263. *             destinationData                Handle in which to store translated data
  264. *             
  265. *  Exit:    dstData                        Handle is resized and filled with data in requested format
  266. }
  267.  
  268. FUNCTION TranslateScrap(sourceDataGetter: GetScrapData; sourceDataGetterRefCon: UNIV Ptr; destinationFormat: ScrapType; destinationData: Handle; progressDialogID: INTEGER): OSErr;
  269.     {$IFC NOT GENERATINGCFM}
  270.     INLINE $700E, $ABFC;
  271.     {$ENDC}
  272.  
  273. {$ALIGN RESET}
  274. {$POP}
  275.  
  276. {$SETC UsingIncludes := TranslationIncludes}
  277.  
  278. {$ENDC} {__TRANSLATION__}
  279.  
  280. {$IFC NOT UsingIncludes}
  281.  END.
  282. {$ENDC}
  283.